class Name
    attr_reader :first, :last
    def initialize(first, last)    
        @first = first
        @last = last
    end
    
    def to_s
        [@first, @last].compact.join(" ")
        # compact - Returns a new array based on the arr with all nil elements removed
    end
end

class Player < ActiveRecord::Base    
    set_primary_key "player_id"
    has_many :pairs, :class_name=>"PairPlayer", :foreign_key=>"player_id"
    
    # using aggreagation with Name class
    composed_of :name,
                :class_name => Name,
                :mapping => 
                    [   %w(first_name first),
                        %w(last_name last)
                    ]
   def self.sem_content_columns
      ['name','rank','created_at', 'location']
   end
   
   def location
      loc = read_attribute :location
      loc ? loc : 'Omsk' 
   end
   
   def rank
      return Rank.find(self.rank_id).rank.to_i
   end   
end
